#include <iostream>
#include <string>
#include <jsoncpp/json/json.h>
#include <fstream>
using namespace std;


struct Stu
{
    string name;
    int age;
    double weight;

    void Print()
    {
        cout <<name<<endl;
        cout <<age<<endl;
        cout <<weight<<endl;

    }
};


int main()
{
    //读文件
    ifstream in("out.txt");
    if(!in.is_open()) return 1;

    char buffer[1024];
    in.read(buffer,sizeof(buffer));
    in.close();

    string str = buffer;
    Json::Value root;
    //把字符串从系统中读出来 ——————反序列化
    Json::Reader reader;
    //把文件流中的数据反序列化到 root 中
    bool ret = reader.parse(str,root);
    Stu stu;
    stu.name = root["name"].asString();
    stu.age = root["age"].asInt();
    stu.weight = root["weight"].asDouble();

    stu.Print();
    

}




// int main()
// {
//     Stu stu = {"liusong",18,10.00};
//     //结构化数据转字符串 
//     Json::Value root;
//     root["name"] = stu.name;
//     root["age"] = stu.age;
//     root["weight"] = stu.weight;



//     ofstream out("out.txt");
//     Json::StyledWriter writer;
//     string str = writer.write(root);
//     out << str;
//     out.close();
//     //序列化数据
//     // Json::FastWriter writer;
//     // string ret = writer.write(root);
//     // cout << ret;


// }